import api from "@/fetch/api.js"

const state = {
    booklist: [],
    bookdetail: {}
}

const getters = {
    booklist(state) {
        return state.booklist;
    },
    bookdetail(state) {
        return state.bookdetail;
    }
}

const mutations = {
    set_booklist(state, data) {
        state.booklist = data;
    },
    set_bookdetail(state, data) {
        state.bookdetail = data;
    }
}

const actions = {
    get_booklist({commit}, params) {
        api.booklist(params).then(res => {
            commit('set_booklist', res.msg);
        });
    },
    get_bookdetail({commit}, params) {
        api.bookdetail(params).then(res => {
            commit('set_bookdetail', res.book);
        });
    }
}

export default {
    namespaced:true,
    state,
    getters,
    mutations,
    actions
}